package magicboard.classifier.features
{
  import flash.geom.Point;
  
  import flexunit.framework.TestCase;
  import flexunit.framework.TestSuite;
  
  import magicboard.classifier.feature.features.EndSinFeature;
  import magicboard.model.InkStroke;
  
  public class EndSinTestCase extends TestCase
  {
    // --------------------------------------------------------------------------------------------	
    public function EndSinTestCase(methodName:String) {
   	 super( methodName );
    }

    // --------------------------------------------------------------------------------------------	
    public static function suite():TestSuite {
   		var ts:TestSuite = new TestSuite();
   		
   		ts.addTest( new EndSinTestCase( "testalpha0" ) );
   		ts.addTest( new EndSinTestCase( "testalpha45" ) );
   		ts.addTest( new EndSinTestCase( "testalpha90" ) );
   		ts.addTest( new EndSinTestCase( "testalpha135" ) );
   		ts.addTest( new EndSinTestCase( "testalpha180" ) );
   		ts.addTest( new EndSinTestCase( "testalpha225" ) );
   		ts.addTest( new EndSinTestCase( "testalpha270" ) );
   		ts.addTest( new EndSinTestCase( "testalpha315" ) );
   		
   		return ts;
   	}
   	
    // --------------------------------------------------------------------------------------------
		private function sinangle(angle:Number):Number{
			return 0.5 * (Math.sin(angle/180 * Math.PI) + 1);
		}   	

  
    // --------------------------------------------------------------------------------------------
		private function assertRound(expected:Number, received:Number):void{
			assertEquals(Math.round(expected*100), Math.round(received*100));
		}   	

  
    // --------------------------------------------------------------------------------------------
		public function testalpha0():void {

			var fe:EndSinFeature = new EndSinFeature();
			var stroke:InkStroke = new InkStroke();
		
			stroke.addPoint(new Point(56,0));
			stroke.addPoint(new Point(10,0));
			stroke.addPoint(new Point(0,0));
			
			assertRound(sinangle(0), fe.extract(stroke)); 
 		}
  		
    // --------------------------------------------------------------------------------------------
		public function testalpha45():void {

			var fe:EndSinFeature = new EndSinFeature();
			var stroke:InkStroke = new InkStroke();
		
			stroke.addPoint(new Point(56,56));
			stroke.addPoint(new Point(10,10));
			stroke.addPoint(new Point(1,1));
			
			assertRound(sinangle(45), fe.extract(stroke)); 
 		}
  		
    // --------------------------------------------------------------------------------------------
		public function testalpha90():void {

			var fe:EndSinFeature = new EndSinFeature();
			var stroke:InkStroke = new InkStroke();
		
			stroke.addPoint(new Point(1,56));
			stroke.addPoint(new Point(1,10));
			stroke.addPoint(new Point(1,1));
			
			assertRound(sinangle(90), fe.extract(stroke)); 
 		}
  		
     // --------------------------------------------------------------------------------------------
		public function testalpha135():void {

			var fe:EndSinFeature = new EndSinFeature();
			var stroke:InkStroke = new InkStroke();
		
			stroke.addPoint(new Point(-54,56));
			stroke.addPoint(new Point(-8,10));
			stroke.addPoint(new Point(1,1));
			
			assertRound(sinangle(135), fe.extract(stroke)); 
 		}
  		
    // --------------------------------------------------------------------------------------------
		public function testalpha180():void {

			var fe:EndSinFeature = new EndSinFeature();
			var stroke:InkStroke = new InkStroke();
		
			stroke.addPoint(new Point(-56,1));
			stroke.addPoint(new Point(-8,1));
			stroke.addPoint(new Point(1,1));
			
			assertRound(sinangle(180), fe.extract(stroke)); 
 		}
  		
    // --------------------------------------------------------------------------------------------
		public function testalpha225():void {

			var fe:EndSinFeature = new EndSinFeature();
			var stroke:InkStroke = new InkStroke();
		
			stroke.addPoint(new Point(-56,-56));
			stroke.addPoint(new Point(-8,-8));
			stroke.addPoint(new Point(1,1));
			
			assertRound(sinangle(225), fe.extract(stroke)); 
 		}
  		
    // --------------------------------------------------------------------------------------------
		public function testalpha270():void {

			var fe:EndSinFeature = new EndSinFeature();
			var stroke:InkStroke = new InkStroke();
		
			stroke.addPoint(new Point(1,-56));
			stroke.addPoint(new Point(1,-8));
			stroke.addPoint(new Point(1,1));
			
			assertRound(sinangle(270), fe.extract(stroke)); 
 		}
  		
    // --------------------------------------------------------------------------------------------
		public function testalpha315():void {

			var fe:EndSinFeature = new EndSinFeature();
			var stroke:InkStroke = new InkStroke();
		
			stroke.addPoint(new Point(-54,-54));
			stroke.addPoint(new Point(-8,-8));
			stroke.addPoint(new Point(0,0));
			
			assertRound(sinangle(315), fe.extract(stroke)); 
 		}
  		
	}
}